package fr.umlv.projet.android.getExam;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;

import android.app.IntentService;
import android.content.Intent;
import fr.umlv.projet.android.subject.SubjectPlaneActivity;
import fr.umlv.projet.android.utils.ServerHelper;

public class GetExamService extends IntentService{

	public GetExamService() {
		super("GetExam Service");
	}

	@Override
	protected void onHandleIntent(Intent intent) {
		
		Intent subjectIntent = new Intent(getBaseContext(), SubjectPlaneActivity.class);
		subjectIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		
		String exam = intent.getStringExtra("exam");
		try {
			String reponse = ServerHelper.getExam(exam);
			subjectIntent.putExtra("exam", reponse);
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		startActivity(subjectIntent);
	}

}
